package com.youren.health.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.youren.health.service.SetmealService;
import com.youren.health.utils.OSSUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: health_parent
 * @author: You_ren_a
 * @create: 2020-11-25 17:21
 **/
//@Component
public class CleanImgJob {
    private static Logger log= LoggerFactory.getLogger(CleanImgJob.class);
    @Reference
    private SetmealService setmealService;
    @Scheduled(initialDelay = 3000,fixedDelay = 1800000)
    public void cleanImg() {
        log.info("开始删除图片");
        List<String> aliImgList = OSSUtil.ListFiles();
        log.debug("阿里云上的图片有："+aliImgList.size()+"张");
        List<String> dbImgList = setmealService.findImgList();
        log.debug("数据库的图片有："+dbImgList.size()+"张");
        aliImgList.removeAll(dbImgList);
        log.debug("要删除的图片有："+aliImgList.size()+"张");
        List<String> list = OSSUtil.removeFiles(aliImgList);
        for (String s : list) {
            log.debug(s);
        }
    }
}
